package com.kebabeaters.nakebab.client.ui.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
import com.kebabeaters.nakebab.client.i18n.MessagesConstants;
import com.kebabeaters.nakebab.client.presenter.AddRestaurantPresenter.Display;

public class AddRestaurantView extends ViewImpl implements Display {
	
	@UiField
	protected FlowPanel formPanel;	
	
	private MessagesConstants messages;
	
	@Inject
	public AddRestaurantView(MessagesConstants messages) {
		this.messages = messages;
	}

	@Override
public Widget asWidget() {
		
		final FormPanel form = new FormPanel();
		form.setEncoding(FormPanel.ENCODING_MULTIPART);
		form.setMethod(FormPanel.METHOD_POST);
		form.addStyleName("table-center");
		form.addStyleName("demo-FormPanel");
		
		Grid grid = new Grid(4, 2);
		
		grid.setWidget(0, 0, new Label("Nazwa"));
		TextBox name = new TextBox();
		name.setName("name");
		grid.setWidget(0, 1, name);		
		
		grid.setWidget(1, 0, new Label("Adres"));
		TextArea address = new TextArea();
		address.setName("address");
		grid.setWidget(1, 1, address);

		grid.setWidget(2, 0, new Label("Komentarz"));
		TextArea comment = new TextArea();
		comment.setName("comment");
		grid.setWidget(2, 1, comment);
		
		{
			Button submit = new Button("Wyślij");			
			
			submit.addClickHandler(new ClickHandler() {
				
				@Override
				public void onClick(ClickEvent event) {
					final PopupPanel popup = new PopupPanel();
					
					FlowPanel popupPanel = new FlowPanel();
					
					popupPanel.add(new Label(messages.notImplementedMessage()));
					
					Button button = new Button("OK");
					button.addClickHandler(new ClickHandler() {
						
						@Override
						public void onClick(ClickEvent event) {
							popup.hide();
						}
					});
					popupPanel.add(button);
					
					popup.setWidget(popupPanel);

					popup.setPopupPosition(300, 300);
					popup.show();					
				}
			});
			
			grid.setWidget(3, 1, submit);
		}

		form.add(grid);
		
		return form;
	}

}
